Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent background for tooltips, dropdowns etc. #1583

Merged
merged 5 commits into from
Feb 18, 2021

Conversation

Ciantic
Copy link
Collaborator

@Ciantic Ciantic commented Feb 11, 2021

Goal is to allow create overlay windows, such as tooltips, dropdowns etc. by simply setting the backround of the window to transparent. It also allowes to do windows without decorations (#427) and would be better way for creating overlay widgets (#1577). Additionally #1249.

https://xi.zulipchat.com/#narrow/stream/147926-druid/topic/Semi-transparent.20windows.20without.20titlebars

For instance transparency is required to make tooltip shaped window:

Or dropdown window with custom shadows:

Or if you want to make your UI go full WinAmp style from 90's:


New API for window builder transparent:

    let main_window = WindowDesc::new(build_root_widget())
        .title("Hello World!")
        .transparent(true) // <-- NEW SETTING HERE
        .window_size((400.0, 400.0));

To get fully transparent background, hide also the title bar with show_titlebar(false).


Changes include a simple example in examples/transparency.rs, currently it renders a test widget like this on a transparent background:


Note about Windows 10 code changes: This feature is not supposed to change any behavior of non-transparent windows at all, the opaque windows still should use the same code as before.

The method I chose follows this tutorial: "Windows with C++ : High-Performance Window Layering Using the Windows Composition Engine", it's the most recent, I asked about that in window-rs repo.

Included are Mac support by @rjwittams, and Linux (GTK) support by @JAicewizard. X11 and web support is stubbed.

druid-shell/src/platform/windows/window.rs Show resolved Hide resolved
druid/examples/transparency.rs Outdated Show resolved Hide resolved
druid/examples/transparency.rs Outdated Show resolved Hide resolved
druid/examples/transparency.rs Outdated Show resolved Hide resolved
druid/src/app.rs Show resolved Hide resolved
@JAicewizard
Copy link
Contributor

you should also ad stubs for any unsupported platform

@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 14, 2021

This is now ready for review 🚢, only thing I'm annoyed is the amount of commits there, I think we can't squash this as there are contributions from others, and GitHub doesn't allow squashing only some from the older commits?

I'm trying to re-base this so that commits from different people are not squashed.

@JAicewizard
Copy link
Contributor

local squash + force push ;)

@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 14, 2021

I'm rebasing this, currently a total mess.

@Ciantic Ciantic marked this pull request as ready for review February 14, 2021 20:05
@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 14, 2021

Now I have rebased / squashed this.

I think it's now final. 🚢

@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 14, 2021

Note for posterity, we removed two spurious println! lines with force push right there. The Github log doesn't make this very clear if we don't do real commits.

@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 14, 2021

@cmyr I think this is ready for review.

@Ciantic Ciantic requested a review from cmyr February 14, 2021 22:00
@cmyr cmyr added the S-needs-review waits for review label Feb 15, 2021
@raphlinus
Copy link
Contributor

This causes failure on Windows 7, STATUS_DLL_NOT_FOUND in particular. I haven't investigated in detail, but it's most likely the dependency on DirectComposition. Since it's not supported on Windows 7, it needs to be loaded as optional functions. That existed for a long while but was removed in #1191, specifically commit 290f6e4.

@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 16, 2021

Okay we discussed this in Zulip, I'll change the Windows part to make the dependency to composition parts optional.

@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 16, 2021

It's all green again 🟢. I don't have Windows 7 to test, and looks like the CI doesn't test that either, but when you've got time give it a test on Win 7.

If it doesn't work, I may have to get Win 7 running in vbox, I don't want to bother you to test the compilation after my changes.

@raphlinus
Copy link
Contributor

raphlinus commented Feb 16, 2021

It works as expected on 7 - hello works fine, and the "transparency" example isn't transparent but is otherwise functional. You might consider logging a warning in that case. So this is unblocked on me, but still requires someone to review in all the PR's glorious detail.

Ciantic and others added 2 commits February 16, 2021 23:38
Web stub implementation to allow compilation

Signed-off-by: Jari Pennanen <ciantic@oksidi.com>
Signed-off-by: Jari Pennanen <ciantic@oksidi.com>
@Ciantic Ciantic force-pushed the master branch 2 times, most recently from 75635ec to 1ade185 Compare February 16, 2021 22:02
@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 16, 2021

I added the warning if user is using Win 7 and tries transparent, and rebased, squashed my win 7 fix changes.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, a few little observations inline but nothing blocking.

I'm curious if this has been tested on multiple monitors, at all; that seems like a possible source of complications. I'm also slightly scared of macOS, and I'll test again on my laptop with a second monitor when I get home later tonight.

Thanks in any case, this should unblock a lot of other work!

druid-shell/src/platform/windows/window.rs Show resolved Hide resolved
druid-shell/src/platform/windows/window.rs Outdated Show resolved Hide resolved
druid/examples/transparency.rs Outdated Show resolved Hide resolved
@Ciantic
Copy link
Collaborator Author

Ciantic commented Feb 17, 2021

I pushed some changes.

@cmyr
Copy link
Member

cmyr commented Feb 18, 2021

Okay, this looks good to me, thanks again!

@cmyr cmyr merged commit 131b0a6 into linebender:master Feb 18, 2021
richard-uk1 pushed a commit to richard-uk1/druid that referenced this pull request Apr 6, 2021
* Windows with transparent background

* Mac support for transparency

Web stub implementation to allow compilation

Signed-off-by: Jari Pennanen <ciantic@oksidi.com>

* add transparance on linux!!!

Signed-off-by: Jari Pennanen <ciantic@oksidi.com>

* Win 7 transparency fix: optionalize DCompositionCreateDevice

* Transparency touch-ups

Co-authored-by: Robert Wittams <robert@wittams.com>
Co-authored-by: jaap aarts <jaap.aarts1@gmail.com>
@maan2003 maan2003 removed the S-needs-review waits for review label May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overlay Widgets Transparent Window Background Color Windows without decorations
6 participants